import numpy as np
import matplotlib.pyplot as plt
import sklearn.linear_model as linear_model

np.random.seed(42)

x = [np.random.random() for i in range(500)]
size = len(x)
ns = np.random.normal(0,1,size)
y = [x[i]+ns[i] for i in range(size)]

model_x2y = linear_model.LinearRegression()
model_x2y.fit([[i] for i in x],y)
ys = model_x2y.predict([[i] for i in x])
print(model_x2y.coef_)
print(model_x2y.intercept_)
fig = plt.figure()
plt.plot(x,y,c='blue')
plt.plot(x,ys,c='red')
# plt.imshow()
plt.savefig('./x2y.jpg')
plt.show()
